﻿<%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="AddNewInvoice.aspx.cs"
    Inherits="Web.Invoice.AddNewInvoice" Title="Xtablish CRM / New Invoice" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="Con1" runat="Server">
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function WebForm_OnSubmit() {
                if (typeof (ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) {
                    $("#validation_dialog").dialog({
                        title: "Validation Error!",
                        modal: true,
                        resizable: false,
                        buttons: {
                            Close: function () {
                                $(this).dialog('close');
                            }
                        }
                    });
                    return false;
                }
                return true;
            }
            function CancelClick() {
                window.location.assign(document.getElementById('<%= hdntxtPrevPage.ClientID %>').value);
            }
            function disableKeyPress(evt) {
                return false;
            }
            function isNumberKey(evt) {
                var charCode = (evt.which) ? evt.which : event.keyCode
                if (charCode > 31 && (charCode < 48 || charCode > 57))
                    return false;
                return true;
            }

            var currentIndex = -1;
            var quantityindexchange = -1;
            var index2 = -1;
            var index1 = -1;
            var index = -1;
            function Select(i) {
                index = currentIndex = quantityindexchange = index2 = index1 = parseInt(i);
            }

            function OnClientClose(oWnd, args) {
                //get the transferred arguments
                var arg = args.get_argument();
                if (arg) {
                    var searchType = arg.SearchType;
                    if (searchType == "InvoiceNumber") {
                        var oppName = arg.InvoiceNumber;
                        var oppID = arg.InvoiceNumberID;
                    }
                    else if (searchType == "Contact") {
                        var ContactName = arg.ContactName;
                        var ContactID = arg.ContactID;
                        document.getElementById('<%= hdntxtConName.ClientID %>').value = ContactName;
                        document.getElementById('<%= hdntxtConID.ClientID %>').value = ContactID;
                        document.getElementById('<%= txtContactName.ClientID %>').value = ContactName;
                    }

                    else if (searchType == "Organization") {
                        var orgName = arg.OrgName;
                        var orgID = arg.OrgID;
                        document.getElementById('<%= hdntxtOrgName.ClientID %>').value = orgName;
                        document.getElementById('<%= hdntxtOrgID.ClientID %>').value = orgID;
                        document.getElementById('<%= txtOrganizationName.ClientID %>').value = orgName;
                    }
                    else if (searchType == "Product") {
                        var productImage = arg.ProductImage;
                        var productID = arg.ProductID;
                        var productName = arg.ProductName;
                        var productDes = arg.ProductDes;
                        var productGST = arg.ProductGST;
                        var productUnitPrice = arg.ProductUnitPrice;
                        var productBalance = arg.ProductBalance;
                        document.getElementById('<%= hdntxtProductImage.ClientID %>').value = productImage;
                        document.getElementById('<%= hdntxtProductID.ClientID %>').value = productID;
                        document.getElementById('<%= hdntxtProductName.ClientID %>').value = productName;
                        document.getElementById('<%= hdntxtProductDes.ClientID %>').value = productDes;
                        document.getElementById('<%= hdntxtProductGST.ClientID %>').value = productGST;
                        document.getElementById('<%= hdntxtProductUnitPrice.ClientID %>').value = productUnitPrice;
                        document.getElementById('<%= hdntxtProductBalance.ClientID %>').value = productBalance;
                    }
    }
    document.getElementById('<%= hdntxtCurrentRow.ClientID %>').value = index;
                document.getElementById('<%= btnCloseRadWin.ClientID %>').click();

            }

            function clearConName() {
                document.getElementById('<%= hdntxtConName.ClientID %>').value = null;
                document.getElementById('<%= hdntxtConID.ClientID %>').value = null;
                document.getElementById('<%= txtContactName.ClientID %>').value = null;
            }

            function clearOrgName() {
                document.getElementById('<%= hdntxtOrgName.ClientID %>').value = null;
                document.getElementById('<%= hdntxtOrgID.ClientID %>').value = null;
                document.getElementById('<%= txtOrganizationName.ClientID %>').value = null;

                document.getElementById('<%= hdntxtConName.ClientID %>').value = null;
                document.getElementById('<%= hdntxtConID.ClientID %>').value = null;
                document.getElementById('<%= txtContactName.ClientID %>').value = null;
            }

            function rbtnPercent_Clicked() {
                var grid = $find("<%= RadGrid1.ClientID %>");
                var masterTableView = grid.get_masterTableView();
                var rbtnPercent, divDiscountPercent, divDiscountPrice;
                var row = masterTableView.get_dataItems()[index];
                var rntxtDiscountPercent = row.findControl("rntxtDiscountPercent");
                var rntxtDiscountPrice = row.findControl("rntxtDiscountPrice");
                var divDiscountPercent = row.findElement("divDiscountPercent");
                var divDiscountPrice = row.findElement("divDiscountPrice");
                var rbtnPercent = row.findControl("rbtnPercent");
                if (rbtnPercent.get_checked()) {
                    divDiscountPercent.style.display = "block";
                    divDiscountPrice.style.display = "none";
                    rntxtDiscountPercent.set_value(rntxtDiscountPrice.get_value());
                }
                else {
                    divDiscountPercent.style.display = "none";
                    divDiscountPrice.style.display = "block";
                    rntxtDiscountPrice.set_value(rntxtDiscountPercent.get_value());
                }
                valueChanged();
            }
            var Quantity = 0;
            function valueChanged() {
                var grid = $find("<%= RadGrid1.ClientID %>");
                var masterTableView = grid.get_masterTableView();
                var rbtnPercent, divDiscountPercent, divDiscountPrice;
                var ROWs = masterTableView.get_dataItems();
                var row;
                if (quantityindexchange == currentIndex) {
                    row = masterTableView.get_dataItems()[index];
                }
                else {
                    row = ROWs[quantityindexchange];
                }
                var rntxtUnitPrice = row.findControl("rntxtUnitPrice");
                var rntxtQuantity = row.findControl("rntxtQuantity");
                var rntxtBalance = row.findControl("rntxtBalance");
                var rntxtDiscountPercent = row.findControl("rntxtDiscountPercent");
                var rntxtDiscountPrice = row.findControl("rntxtDiscountPrice");
                var rbtnPercent = row.findControl("rbtnPercent");
                var rntxtGST = row.findControl("rntxtGST");
                var rntxtTotalPrice = row.findControl("rntxtTotalPrice");
                var discountprice = 0;
                var totalprice = rntxtUnitPrice.get_value() * rntxtQuantity.get_value();
                totalprice = totalprice + totalprice * (rntxtGST.get_value() / 100.0);
                if (rbtnPercent.get_checked()) {
                    discountprice = (totalprice) * (rntxtDiscountPercent.get_value() / 100.0);
                }
                else {
                    discountprice = rntxtDiscountPrice.get_value();
                }
                totalprice = totalprice - discountprice;

                if (totalprice < 0) totalprice = 0;
                rntxtTotalPrice.set_value(totalprice);
                quantityindexchange = currentIndex;
            }


            function LimitOptions(sender, eventArgs) {

                var grid = $find("<%= RadGrid1.ClientID %>");
        var masterTableView = grid.get_masterTableView();
        var ROWs = masterTableView.get_dataItems();
        var row = masterTableView.get_dataItems()[index];
        if (index1 != currentIndex) {
            row = ROWs[index1];
        }
        var proID = row.getDataKeyValue("ProductID");
        var rntxtBalance = row.findControl("rntxtBalance");
        var rntxtCurrentBalance = row.findControl("rntxtCurrentBalance");
        if (eventArgs.get_newValue() > rntxtBalance.get_value()) {
            eventArgs.set_newValue(eventArgs.get_oldValue());
            var url = "../Product/EditProduct.aspx?id=" + proID;
            radConfirmAddMoreQuantity("You must add more quantity for this product !", url);
        }
        else {
            if (index1 != currentIndex)
                quantityindexchange = index1;
            else
                quantityindexchange = currentIndex;
            rntxtCurrentBalance.set_value(rntxtBalance.get_value() - eventArgs.get_newValue());
            index1 = currentIndex;
        }
    }
    function CurrentBalanceChange(sender, eventArgs) {
        var grid = $find("<%= RadGrid1.ClientID %>");
        var masterTableView = grid.get_masterTableView();
        var ROWs = masterTableView.get_dataItems();
        var row = masterTableView.get_dataItems()[index];
        if (index2 != -1)
            row = ROWs[index2];
        var CurrentBalance = row.findControl("rntxtCurrentBalance");
        var proID = row.getDataKeyValue("ProductID");
        for (var i = index2 + 1 ; i < ROWs.length; i++) {
            var proID2 = ROWs[i].getDataKeyValue("ProductID");
            if (proID == proID2) {
                var Balance = ROWs[i].findControl("rntxtBalance");
                var currentBalance = ROWs[i].findControl("rntxtCurrentBalance");
                var quantity = ROWs[i].findControl("rntxtQuantity");
                index2 = i;
                Balance.set_value(CurrentBalance.get_value());
                currentBalance.set_value(Balance.get_value() - quantity.get_value());
                if (Balance.get_value() <= 0) {
                    index1 = i;
                    quantity.set_value(0);
                }
                else {
                    if (quantity.get_value() > Balance.get_value()) {
                        index1 = i;
                        quantity.set_value(Balance.get_value());
                    }
                }
                break;
            }
        }
        index2 = currentIndex;
    }
    var sumInput = null;
    function Load(sender, args) {
        sumInput = sender;
    }
    function OnBlur(sender, args) {
        if (sender.get_value() == "") {
            sender.set_value("0");
        }

    }
    function TotalPriceOnValueChanged(sender, args) {
        var tempValue = 0.0;
        var grid = $find("<%= RadGrid1.ClientID %>");
        var masterTableView = grid.get_masterTableView();
        var rows = masterTableView.get_dataItems();
        for (var i = 0; i < rows.length; i++) {
            var rntxtTotalPrice = rows[i].findControl("rntxtTotalPrice");
            tempValue += rntxtTotalPrice.get_value();
        }
        sumInput.set_value(tempValue);
    }
    function openProductSearchWindow(rowIndex) {
        index = rowIndex;
        openWin("../SearchPopup/Product.aspx", "rwProduct");
        return false;
    }
    
    function openRadWin(url, formname) {
        var orgID = document.getElementById('<%= hdntxtOrgID.ClientID %>').value;
        var orgName = document.getElementById('<%= hdntxtOrgName.ClientID %>').value;
        if (orgID != "")
            openWin(url + "?OrgID=" + orgID + "&OrgName=" + orgName, formname);
        else
            ShowMessage("Please choose company name first !");
    }
        </script>
    </telerik:RadCodeBlock>

    <asp:HiddenField ID="hdntxtPrevPage" runat="server"></asp:HiddenField>
    <asp:HiddenField ID="hdntxtConName" runat="server"></asp:HiddenField>
    <asp:HiddenField ID="hdntxtConID" runat="server"></asp:HiddenField>
    <asp:HiddenField ID="hdntxtOrgName" runat="server"></asp:HiddenField>
    <asp:HiddenField ID="hdntxtOrgID" runat="server"></asp:HiddenField>

    <asp:HiddenField ID="hdntxtInvoiceID" runat="server"></asp:HiddenField>
    <asp:HiddenField ID="hdntxtPrint" runat="server"></asp:HiddenField>

    <asp:HiddenField ID="hdntxtProductID" runat="server"></asp:HiddenField>
    <asp:HiddenField ID="hdntxtProductName" runat="server"></asp:HiddenField>
    <asp:HiddenField ID="hdntxtProductDes" runat="server"></asp:HiddenField>
    <asp:HiddenField ID="hdntxtProductGST" runat="server"></asp:HiddenField>
    <asp:HiddenField ID="hdntxtProductImage" runat="server"></asp:HiddenField>
    <asp:HiddenField ID="hdntxtProductUnitPrice" runat="server"></asp:HiddenField>
    <asp:HiddenField ID="hdntxtProductBalance" runat="server"></asp:HiddenField>

    <asp:HiddenField ID="hdntxtCurrentRow" runat="server"></asp:HiddenField>

    <div class="register">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-6">
                    <h3>Creating New Invoice</h3>
                </div>
                <div class="col-md-6 btn-edit">
                    <asp:LinkButton ID="lbtnPrint" runat="server" Style="display: none" >
                    <image src="../Images/printer.png" style="width: 16px; height: 16px"/>
                    </asp:LinkButton>
                    <asp:LinkButton ID="btnTop_SaveAsDraft" type="button" runat="server" class="btn btn-defaul" OnClick="btn_SaveAsDraft_Click">
                        <img src="../Images/draft_text.png" style="width: 18px; height: 18px" />
                        Save As Draft
                    </asp:LinkButton>
                    <asp:LinkButton ID="btnTop_Save" type="button" runat="server" class="btn btn-defaul" OnClick="btn_Save_Click">
                        <img src="../Images/save.png" style="width: 18px; height: 18px" />
                        Save
                    </asp:LinkButton>
                    <div id="validation_dialog" style="display: none">
                        <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
                    </div>
                    <asp:LinkButton ID="btnTop_Cancel" type="button" runat="server" class="btn btn-defaul" OnClientClick="CancelClick()" CausesValidation="false">
                        <img src="../Images/back.png" style="width: 18px; height: 18px" />
                        Back
                    </asp:LinkButton>
                </div>
            </div>

            <!-- end row -->
            <div class="row">
                <div class="edit-form highlight">
                    <div class="control-group">
                        <h4>Invoice Details</h4>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label"><span class="red-star">*</span>Company Name </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtOrganizationName" runat="server" class="form-control form-fl" onkeypress="return disableKeyPress(event)" data-validate="required" />
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" Display="None" ControlToValidate="txtOrganizationName"
                                        runat="server" ErrorMessage="Company Name is required."></asp:RequiredFieldValidator>
                                    <div class="btn-sl" style="padding-top: 2px">
                                        <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="openWin('../SearchPopUp/Organization.aspx?', 'rwOrganization'); return false;" ToolTip="Search">
                                            <img src="../Images/search.png" style="width: 18px; height: 18px" />
                                        </asp:LinkButton>
                                        <asp:LinkButton ID="LinkButton2" runat="server" OnClientClick="clearOrgName();return false;" ToolTip="Clear">
                                            <img src="../Images/delete.png" style="width: 16px; height: 16px" />
                                        </asp:LinkButton>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Contact Name </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtContactName" runat="server" class="form-control form-fl" onkeypress="return disableKeyPress(event)" />
                                    <div class="btn-sl" style="padding-top: 2px">
                                        <asp:LinkButton ID="LinkButton3" runat="server" OnClientClick="openRadWin('../SearchPopUp/Contact.aspx', 'rwContact'); return false;" ToolTip="Search">
                                            <img src="../Images/search.png" style="width: 18px; height: 18px" />
                                        </asp:LinkButton>
                                        <asp:LinkButton ID="LinkButton4" runat="server" OnClientClick="clearConName();return false;" ToolTip="Clear">
                                            <img src="../Images/delete.png" style="width: 16px; height: 16px" />
                                        </asp:LinkButton>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Customer No</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtCustomerNo" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Status </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <telerik:RadComboBox ID="ddlStatus" runat="server" DataTextField="STATUS_NAME" DataValueField="ID" cl="form-control"
                                        Width="60%" Filter="StartsWith" MaxHeight="700px" />

                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Invoice Date</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <telerik:RadDatePicker ID="dpInvoiceDate" runat="server" Width="50%">
                                        <DateInput ReadOnly="true" ID="RadDateInput1" runat="server">
                                        </DateInput>
                                        <Calendar ReadOnly="true" ID="Calendar1" runat="server" UseColumnHeadersAsSelectors="False"
                                            UseRowHeadersAsSelectors="False" ViewSelectorText="x">
                                            <SpecialDays>
                                                <telerik:RadCalendarDay Repeatable="Today" ItemStyle-CssClass="rcToday">
                                                </telerik:RadCalendarDay>
                                            </SpecialDays>
                                        </Calendar>
                                    </telerik:RadDatePicker>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Due Date</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <telerik:RadDatePicker ID="dpDueDate" runat="server" Width="50%">
                                        <DateInput ReadOnly="true" ID="DateInput1" runat="server">
                                        </DateInput>
                                        <Calendar ReadOnly="true" ID="Calendar2" runat="server" UseColumnHeadersAsSelectors="False"
                                            UseRowHeadersAsSelectors="False" ViewSelectorText="x">
                                            <SpecialDays>
                                                <telerik:RadCalendarDay Repeatable="Today" ItemStyle-CssClass="rcToday">
                                                </telerik:RadCalendarDay>
                                            </SpecialDays>
                                        </Calendar>
                                    </telerik:RadDatePicker>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Purchase Order </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtPurchaseOrder" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Sales Commission </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <telerik:RadNumericTextBox ShowSpinButtons="false" Type="Percent" ID="rntxtCommission" runat="server"
                                        Width="30%" CssClass="RadNumbericText" MinValue="0" Value="0">
                                        <ClientEvents OnBlur="OnBlur" />
                                    </telerik:RadNumericTextBox>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group" id="divAssignTo" runat="server">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label"><span class="red-star">*</span>Assigned To </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <telerik:RadComboBox ID="ddlAssignedTo" runat="server" class="form-control"
                                        Width="60%" Filter="StartsWith" MaxHeight="700px" />
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>
            <!-- end row -->
            <div class="row">
                <div class="edit-form highlight">
                    <div class="control-group">
                        <h4>Address Details</h4>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label"><span class="red-star">*</span>Office Address </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtOfficeAddress" runat="server" TextMode="MultiLine" class="form-control" Rows="1" data-validate="required"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" Display="None" ControlToValidate="txtOfficeAddress"
                                        runat="server" ErrorMessage="Office address is required."></asp:RequiredFieldValidator>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label"><span class="red-star">*</span>Home Address </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtHomeAddress" runat="server" TextMode="MultiLine" class="form-control" Rows="1" data-validate="required"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" Display="None" ControlToValidate="txtHomeAddress"
                                        runat="server" ErrorMessage="Home address is required."></asp:RequiredFieldValidator>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Office PO Box</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtOfficePOBox" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Home PO Box</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtHomePOBox" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Office City</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtOfficeCity" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Home City</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtHomeCity" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Office State</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtOfficeState" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Home State</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtHomeState" runat="server" class="form-control" />
                                </div>
                            </div>

                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Office Postal Code </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtOfficePostalCode" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Home Postal Code</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtHomePostalCode" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>

                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Office Country </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtOfficeCountry" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Home Country </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtHomeCountry" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>

            <!-- end row -->
            <div class="row">
                <div class="edit-form highlight">
                    <div class="control-group">
                        <h4>Terms & Conditions</h4>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Terms & Conditions</label>
                            </div>
                            <div class="col-md-8">
                                <div class="row" style="padding-bottom: 5px;">
                                    <div class="col-md-5">
                                        <div class="controls">
                                            <telerik:RadComboBox ID="ddlTermsAndConditions" runat="server" class="form-control" DataValueField="ID" AutoPostBack="true" DataTextField="NAME"
                                                OnSelectedIndexChanged="SelectedIndexChanged" Width="100%" Filter="StartsWith" MaxHeight="700px" CausesValidation="false" />
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="controls">
                                            <asp:TextBox ID="txtTermsAndConditions" runat="server" TextMode="MultiLine" class="form-control" Rows="1" Width="100%"></asp:TextBox>
                                        </div>
                                    </div>
                                </div>

                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>

            <!-- end row -->
            <div class="row">
                <div class="edit-form highlight">
                    <div class="control-group">
                        <h4>Description Details</h4>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Descriptions</label>
                            </div>
                            <div class="col-md-8">
                                <div class="row" style="padding-bottom: 5px;">
                                    <div class="col-md-5">
                                        <div class="controls">
                                            <telerik:RadComboBox ID="ddlDescriptions" runat="server" class="form-control" DataValueField="ID" AutoPostBack="true" DataTextField="DESCRIPTION_NAME"
                                                OnSelectedIndexChanged="SelectedIndexChanged" Width="100%" Filter="StartsWith" MaxHeight="700px" CausesValidation="false" />

                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="controls">
                                            <asp:TextBox ID="txtDescriptions" runat="server" TextMode="MultiLine" class="form-control" Rows="1" Width="100%"></asp:TextBox>
                                        </div>
                                    </div>
                                </div>

                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>
            <!-- end row-->
            <div class="row">
                <div class="edit-form highlight">
                    <div class="control-group">
                        <h4>Item Details</h4>
                    </div>
                    <div class="col-md-12 combobox-email">
                        <div class="col-md-8 btn-edit">
                            <button id="btnAddProduct" type="button" class="btn btn-defaul" runat="server" onserverclick="btnAddProduct_ServerClick" causesvalidation="false">
                                <img src="../Images/add.png" style="width: 16px; height: 16px" />
                                Add Product
                            </button>
                            <button id="btnCloseRadWin" type="button" class="btn btn-defaul" runat="server" onserverclick="btnCloseRadWin_ServerClick" causesvalidation="false" style="display: none">
                                <img src="../Images/add.png" style="width: 16px; height: 16px" />
                                Add Product
                            </button>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                    <div style="width: 100%">
                        <telerik:RadGrid ID="RadGrid1" ShowStatusBar="True" runat="server" AllowPaging="True" AllowSorting="True" AllowMultiRowSelection="True"
                            AutoGenerateColumns="False" GridLines="None" Width="100%" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand"
                            OnItemDataBound="RadGrid1_ItemDataBound" ShowFooter="True" OnItemCreated="RadGrid1_ItemCreated">
                            <MasterTableView PageSize="10" NoDetailRecordsText="No records" NoMasterRecordsText="No records" ShowHeader="true" TableLayout="Fixed" ClientDataKeyNames="ProductID"
                                DataKeyNames="ID,ProductID,ProductName,UnitPrice">
                                <Columns>
                                    <telerik:GridBoundColumn DataField="ProductID" UniqueName="ProductID" Display="false">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridTemplateColumn HeaderText="Item Image" UniqueName="ITEM_IMAGE">
                                        <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="8.5%" />
                                        <ItemStyle HorizontalAlign="center" Width="8.5%" />
                                        <FooterStyle HorizontalAlign="center" Width="80px" BackColor="LightBlue" Font-Bold="true" />
                                        <ItemTemplate>
                                            <asp:Image ID="productImage" runat="server" ImageUrl='<%# Bind( "IMAGE") %>' Style="width: 80px; height: 80px" />
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="Item Name" UniqueName="Column1" Aggregate="Count" FooterText="Total products: " DataField="ProductName">
                                        <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="18%" />
                                        <ItemStyle Wrap="false" HorizontalAlign="center" Width="18%" CssClass="paddingright" />
                                        <FooterStyle HorizontalAlign="center" Width="18%" BackColor="LightBlue" Font-Bold="true" />
                                        <ItemTemplate>
                                            <div style="width: 100%">
                                                <table style="width: 100%">
                                                    <tr>
                                                        <td style="width: 75%; padding: 0; border-right: none !important">
                                                            <asp:TextBox ID="txtProductName" runat="server" placeholder="Product Name" onkeypress="return disableKeyPress(event)"
                                                                Text='<%# Bind( "ProductName") %>' CssClass="form-control" Width="100%" TextMode="MultiLine" Rows="2"></asp:TextBox>
                                                        </td>
                                                        <td style="width: 25%; padding: 0; text-align: center; border: none !important">
                                                            <asp:LinkButton ID="lbtnProductSearch" runat="server" ToolTip="Search">
                                                                <img src="../Images/search.png" style="width: 18px; height: 18px" />
                                                            </asp:LinkButton>
                                                            <asp:LinkButton ID="lbtnProductClear" CommandName="Clear" runat="server" ToolTip="Clear">
                                                                <img src="../Images/delete.png" style="width: 16px; height: 16px" />
                                                            </asp:LinkButton>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="Item Description" UniqueName="Column1">
                                        <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="17.5%" />
                                        <ItemStyle Wrap="false" HorizontalAlign="center" Width="17.5%" />
                                        <FooterStyle HorizontalAlign="center" Width="17.5%" BackColor="LightBlue" />
                                        <ItemTemplate>
                                            <asp:TextBox ID="txtProductDescription" runat="server" TextMode="MultiLine" placeholder="Product Description" onkeypress="return disableKeyPress(event)"
                                                Text='<%# Bind( "ProductDescription") %>' CssClass="form-control" Rows="2" Width="100%"></asp:TextBox>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="GST(%)" UniqueName="Column1">
                                        <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="7%" />
                                        <ItemStyle HorizontalAlign="center" Width="7%" />
                                        <FooterStyle HorizontalAlign="center" Width="7%" BackColor="LightBlue" />
                                        <ItemTemplate>
                                            <asp:Panel Style="width: 100%" ID="divGST" runat="server">
                                                <telerik:RadNumericTextBox ShowSpinButtons="false" Type="Percent" ID="rntxtGST" runat="server" ClientEvents-OnValueChanged="valueChanged" MinValue="0" OnTextChanged="rntxtGST_TextChanged"
                                                    Width="100%" CssClass="RadNumbericText">
                                                    <ClientEvents OnBlur="OnBlur" />
                                                </telerik:RadNumericTextBox>
                                            </asp:Panel>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="Unit Price" UniqueName="Column1" DataField="UnitPrice">
                                        <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="10%" />
                                        <ItemStyle HorizontalAlign="center" Width="10%" />
                                        <FooterStyle HorizontalAlign="center" Width="10%" BackColor="LightBlue" />
                                        <ItemTemplate>
                                            <telerik:RadNumericTextBox ShowSpinButtons="false" EmptyMessage="$" Type="Currency" ID="rntxtUnitPrice" runat="server" ClientEvents-OnValueChanged="valueChanged" MinValue="0" OnTextChanged="rntxtUnitPrice_TextChanged"
                                                Width="100%" CssClass="RadNumbericText" DbValue='<%# Eval("UnitPrice") %>'>
                                                <ClientEvents OnBlur="OnBlur" />
                                            </telerik:RadNumericTextBox>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="Discount Price" UniqueName="DiscountPrice" DataField="DiscountPrice">
                                        <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="12%" />
                                        <ItemStyle HorizontalAlign="center" Width="12%" />
                                        <FooterStyle HorizontalAlign="center" Width="12%" BackColor="LightBlue" />
                                        <ItemTemplate>
                                            <div style="width: 100%">
                                                <telerik:RadButton ID="rbtnPercent" runat="server" ToggleType="Radio" ButtonType="ToggleButton" OnClientCheckedChanged="rbtnPercent_Clicked"
                                                    GroupName="Radios" AutoPostBack="false" CausesValidation="false" Text="Percent" Checked="true">
                                                </telerik:RadButton>
                                                <telerik:RadButton ID="rbtnPrice" runat="server" ToggleType="Radio" ButtonType="ToggleButton"
                                                    GroupName="Radios" AutoPostBack="false" CausesValidation="false" Text="Price">
                                                </telerik:RadButton>
                                            </div>
                                            <asp:Panel Style="width: 100%" ID="divDiscountPercent" runat="server">
                                                <telerik:RadNumericTextBox ShowSpinButtons="false" Type="Percent" EmptyMessage="Enter Percent" ID="rntxtDiscountPercent" runat="server" OnTextChanged="rntxtDiscountPercent_TextChanged"
                                                    Width="100%" CssClass="RadNumbericText" ClientEvents-OnValueChanged="valueChanged" MinValue="0" IncrementSettings-Step="0.1">
                                                    <ClientEvents OnBlur="OnBlur" />
                                                </telerik:RadNumericTextBox>
                                            </asp:Panel>
                                            <asp:Panel Style="width: 100%; display: none" ID="divDiscountPrice" runat="server">
                                                <telerik:RadNumericTextBox ShowSpinButtons="false" Type="Currency" EmptyMessage="Enter Price" ID="rntxtDiscountPrice" runat="server" OnTextChanged="rntxtDiscountPrice_TextChanged"
                                                    Width="100%" CssClass="RadNumbericText" ClientEvents-OnValueChanged="valueChanged" MinValue="0">
                                                    <ClientEvents OnBlur="OnBlur" />
                                                </telerik:RadNumericTextBox>
                                            </asp:Panel>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="CurrentBalance" UniqueName="CurrentBalance" DataField="CurrentBalance" Display="false">
                                        <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="8%" />
                                        <ItemStyle HorizontalAlign="center" Width="8%" />
                                        <FooterStyle HorizontalAlign="center" Width="3%" BackColor="LightBlue" />
                                        <ItemTemplate>
                                            <telerik:RadNumericTextBox ShowSpinButtons="True" Type="Number" ID="rntxtCurrentBalance" runat="server" OnTextChanged="rntxtCurrentBalance_TextChanged"
                                                Width="80%" CssClass="RadNumbericText" ClientEvents-OnValueChanged="CurrentBalanceChange" MinValue="0">
                                                <ClientEvents OnBlur="OnBlur" />
                                            </telerik:RadNumericTextBox>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="Quantity" UniqueName="Quantity" DataField="Quantity">
                                        <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="7%" />
                                        <ItemStyle HorizontalAlign="center" Width="7%" />
                                        <FooterStyle HorizontalAlign="center" Width="3%" BackColor="LightBlue" />
                                        <ItemTemplate>
                                            <telerik:RadNumericTextBox ShowSpinButtons="false" Type="Number" ID="rntxtQuantity" runat="server" OnTextChanged="rntxtQuantity_TextChanged"
                                                Width="100%" CssClass="RadNumbericText" ClientEvents-OnValueChanged="valueChanged" MinValue="0">
                                                <ClientEvents OnBlur="OnBlur" OnValueChanging="LimitOptions" />
                                            </telerik:RadNumericTextBox>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="Available" UniqueName="BALANCE" DataField="BALANCE">
                                        <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="7%" />
                                        <ItemStyle HorizontalAlign="center" Width="7%" />
                                        <FooterStyle HorizontalAlign="center" Width="3%" BackColor="LightBlue" />
                                        <ItemTemplate>
                                            <telerik:RadNumericTextBox ShowSpinButtons="false" Type="Number" ID="rntxtBalance" runat="server" ReadOnly="true" OnTextChanged="rntxtBalance_TextChanged"
                                                Width="100%" CssClass="RadNumbericText" ClientEvents-OnValueChanged="valueChanged" MinValue="0">
                                                <ClientEvents OnBlur="OnBlur" />
                                            </telerik:RadNumericTextBox>
                                        </ItemTemplate>
                                        <FooterTemplate>
                                            <asp:Label ID="Label1" runat="server" Text="Total:" Font-Bold="true" />
                                        </FooterTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="Total Price" UniqueName="TotalPrice" DataField="TotalPrice">
                                        <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="10%" />
                                        <ItemStyle HorizontalAlign="center" Width="10%" />
                                        <FooterStyle HorizontalAlign="center" Width="10%" BackColor="LightBlue" />
                                        <ItemTemplate>
                                            <telerik:RadNumericTextBox ShowSpinButtons="false" Type="Currency" ID="rntxtTotalPrice" runat="server" ReadOnly="true"
                                                Width="100%" CssClass="RadNumbericText" OnTextChanged="rntxtTotalPrice_TextChanged" ClientEvents-OnValueChanged="TotalPriceOnValueChanged">
                                                <ClientEvents OnBlur="OnBlur" />
                                            </telerik:RadNumericTextBox>
                                        </ItemTemplate>
                                        <FooterTemplate>
                                            <telerik:RadNumericTextBox ID="rntxtTotalPriceFooter" runat="server" ShowSpinButtons="false" Type="Currency" Width="100%"
                                                ReadOnly="true" CssClass="RadNumbericText" LabelWidth="30%">
                                                <ClientEvents OnLoad="Load" />
                                            </telerik:RadNumericTextBox>
                                        </FooterTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn>
                                        <HeaderStyle Font-Bold="true" HorizontalAlign="center" Width="3%" />
                                        <ItemStyle HorizontalAlign="center" Width="3%" />
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lbtnDelete" runat="server" ToolTip="Delete" CommandName="Delete" CausesValidation="false"
                                                OnClientClick="return radConfirmDelete(this, 'Are you sure you want to delete this item ?');">
                                                    <image src="../Images/delete.png" style="width: 16px; height: 16px"/>
                                            </asp:LinkButton>
                                        </ItemTemplate>
                                        <FooterStyle HorizontalAlign="center" Width="3%" BackColor="LightBlue" />
                                    </telerik:GridTemplateColumn>
                                </Columns>
                                <PagerStyle PageSizes="5,10,20,50" PagerTextFormat="{4}<strong>{5}</strong> items in your page"
                                    PageSizeLabelText="Items per page:" AlwaysVisible="true" />
                            </MasterTableView>
                            <PagerStyle Mode="NumericPages"></PagerStyle>
                        </telerik:RadGrid>
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="row">
                <div class="col-md-12 btn-edit">
                    <asp:LinkButton ID="btnBottom_SaveAsDraft" type="button" runat="server" class="btn btn-defaul" OnClick="btn_SaveAsDraft_Click">
                        <img src="../Images/draft_text.png" style="width: 18px; height: 18px" />
                        Save As Draft
                    </asp:LinkButton>
                    <asp:LinkButton ID="btnBottom_Save" class="btn btn-defaul" runat="server" OnClick="btn_Save_Click">
                        <img src="../Images/save.png" style="width: 18px; height: 18px" />
                        Save
                    </asp:LinkButton>
                    <asp:LinkButton ID="btnBottom_Cancel" runat="server" class="btn btn-defaul" OnClientClick="CancelClick()" CausesValidation="false">
                        <img src="../Images/back.png" style="width: 18px; height: 18px" />
                        Back
                    </asp:LinkButton>
                </div>
            </div>
        </div>
    </div>
</asp:Content>

